#include<stdio.h>
#include <stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>
void work()
{
    int cnt=5;
    while(cnt)
    {
        printf("I am child process,pid:%d,ppid:%d,cnt:%d\n",getpid(),getppid(),cnt);
        cnt--;
    }
    
}

int main()
{
    pid_t id=fork();
    if(id==0)
    {
        work();
        exit(0);
    }
    else{
	    sleep(10);    
        //printf("wait before\n");
        pid_t rid=wait(NULL);
        //printf("wait after\n");
        if(rid==id)
        {
            printf("wait success,pid:%d\n",getpid());
        }
        sleep(10);
    }
    
}
